package com.zzf.concurrent.example;

import lombok.extern.slf4j.Slf4j;

/**
 * thread线程
 * @author GaoFeng2017
 * @date 2019/8/4 9:44
 */

@Slf4j
public class ThreadExample {

    public static void main(String[] args) {
        Thread thread = new Thread() {
            @Override
            public void run() {
                read();
            }
        };
        thread.start();
        thread.start();
        write();
    }

    private static void read() {
        log.info("start read, resource will be init");
        for (int i = 0; i < 100; i++) {
            log.info("read {}", i);
            // sleep(1000);
        }
        log.info("finish read");
    }

    private static void write() {
        log.info("start write, resource will be init");
        for (int i = 0; i < 100; i++) {
            log.info("write {}", i);
            // sleep(1000);
        }
        log.info("finish write");
    }

    private static void sleep(long ms) {
        try {
            Thread.sleep(ms);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
